package com.atguigu.bigdata.spark.core.acc

import org.apache.spark.util.LongAccumulator
import org.apache.spark.{SparkConf, SparkContext}

/**
  * create by undeRdoG on  2021-06-14  17:46
  * 凡心所向，素履以往，生如逆旅，一苇以航。
  */
object Spark01_ACC {

  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf().setAppName("RDD").setMaster("local[*]")
    val sc = new SparkContext(sparkConf)


    val rdd = sc.makeRDD(List(1,2,3,4))

    val sumACC: LongAccumulator = sc.longAccumulator("ACC")

    rdd.foreach(
      num => {
        sumACC.add(num)
      }
    )

    println(sumACC.value)
  }

}
